﻿using Interface;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    /// <summary>
    /// 读取配置工厂
    /// </summary>
    public class SimlpFactory
    {
        private static string IDBHelperConfig = ConfigurationManager.AppSettings["IDBHelperConfig"];//  读取配置文件
        private static string DllName = IDBHelperConfig.Split(',')[1];//逗号分割
        private static string TypeName = IDBHelperConfig.Split(',')[0];
        public static IDBHelper CreateInstentce()
        {
            //动态加载类型
            Assembly assembly = Assembly.Load(DllName); //dll名称
            //获取类型
            Type type = assembly.GetType(TypeName);//命名空间+类名
            //创建对象
            object oDbHelper = Activator.CreateInstance(type);

            return oDbHelper as IDBHelper;
        }
    }
}
